package com.company.myfirstjmixproject.entity.bom;

import com.company.myfirstjmixproject.entity.enums.ComponentUomEnum;
import io.jmix.core.entity.annotation.JmixGeneratedValue;
import io.jmix.core.metamodel.annotation.JmixEntity;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.UUID;

@JmixEntity
@Table(name = "MST_BOM_DETAIL")
@Entity
public class BomDetail {
    @JmixGeneratedValue
    @Column(name = "ID", nullable = false)
    @Id
    private UUID id;

    @Column(name = "VERSION", nullable = false)
    @Version
    private Integer version;

    @JoinColumn(name = "BOM_ID", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    @NotNull
    private BomHeader bomHeader;

    @JoinColumn(name = "COMPONENT_CODE", nullable = false)
    @OneToOne(optional = false, fetch = FetchType.LAZY)
    @NotNull
    private Item item;

    @Column(name = "COMPONENT_UOM", nullable = false)
    private String componentUom;

    @Column(name = "COMPONENT_QTY", nullable = false)
    private BigDecimal componentQty;

    @Column(name = "SCRAP_RATIO")
    private Integer scrapRatio;

    public void setComponentQty(BigDecimal componentQty) {
        this.componentQty = componentQty;
    }

    public BigDecimal getComponentQty() {
        return componentQty;
    }

    public void setScrapRatio(Integer scrapRatio) {
        this.scrapRatio = scrapRatio;
    }

    public Integer getScrapRatio() {
        return scrapRatio;
    }

    public void setComponentUom(ComponentUomEnum componentUom) {
        this.componentUom = componentUom == null ? null : componentUom.getId();
    }

    public ComponentUomEnum getComponentUom() {
        return componentUom == null ? null : ComponentUomEnum.fromId(componentUom);
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public void setBomHeader(BomHeader bomHeader) {
        this.bomHeader = bomHeader;
    }

    public Item getItem() {
        return item;
    }


    public BomHeader getBomHeader() {
        return bomHeader;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public UUID getId() {
        return id;
    }

    public void setId(UUID id) {
        this.id = id;
    }
}